home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 2 / csmp-v2-006.txt < prev    next >
Text File  |  1995-06-30  |  44KB  |  1,228 lines

  1. C.S.M.P. Digest             Wed, 27 Jan 93       Volume 2 : Issue 6
  2.  
  3. Today's Topics:
  4.  
  5.     Driving mac program from another
  6.     Detecting reboot or startup
  7.     Software control of landscape/not landscape
  8.     Preloading ALL code segments...?
  9.  
  10.  
  11.  
  12. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  13.  
  14. The digest is a collection of article threads from the internet newsgroup
  15. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  16. regularly and want an archive of the discussions.  If you don't know what a
  17. newsgroup is, you probably don't have access to it.  Ask your systems
  18. administrator(s) for details.  If you don't have access to news, there is
  19. no way that I know of for you to post articles to the group.
  20.  
  21. Each issue of the digest contains one or more sets of articles (called
  22. threads), with each set corresponding to a 'discussion' of a particular
  23. subject.  The articles are not edited; all articles included in this digest
  24. are in their original posted form (as received by our news server at
  25. cs.uoregon.edu).  Article threads are not added to the digest until the last
  26. article added to the thread is at least one month old (this is to ensure that
  27. the thread is dead before adding it to the digest).  Article threads that
  28. consist of only one message are generally not included in the digest.
  29.  
  30. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  31. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  32. file /pub/mac/csmp-digest/README before downloading any files.  The most
  33. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  34. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  35. archive has a mail server; send a message with the text '$MACarch help' (no
  36. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  37.  
  38. The digest is also available via email.  Just send a note saying that you
  39. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  40. automatically receive each new issue as it is created.  Sorry, back issues
  41. are not available through the mailing list.
  42.  
  43. Send administrative mail to mkelly@cs.uoregon.edu.
  44.  
  45.  
  46. -------------------------------------------------------
  47.  
  48. From: ray@philmtl.philips.ca (Ray Dunn)
  49. Subject: Driving mac program from another
  50. Date: 18 Dec 92 04:14:29 GMT
  51. Organization: Not Philips.
  52.  
  53. Question from someone fairly Mac illiterate but who has a serious need to
  54. know:
  55.  
  56. Given a Mac program which normally takes much mouse events and keyboard
  57. input, is it possible (easily/with difficulty) to have that program run
  58. automatically with the input being generated by another program?
  59.  
  60. To save time, I'd appreciate an email answer, and will summarize replies
  61. back to here.
  62.  
  63. Thanks.
  64. - -- 
  65. Ray Dunn at home        |  Beaconsfield, Quebec  |  Phone: (514) 630 3749
  66. ray@philmtl.philips.ca  |  ray@cam.org           |  uunet!sobeco!philmtl!ray
  67.  
  68. +++++++++++++++++++++++++++
  69.  
  70. From: d88-jwa@dront.nada.kth.se (Jon Wtte)
  71. Date: 18 Dec 92 17:50:34 GMT
  72. Organization: Royal Institute of Technology, Stockholm, Sweden
  73.  
  74. In <1992Dec18.041429.22979@philmtl.philips.ca> ray@philmtl.philips.ca (Ray Dunn) writes:
  75.  
  76. >Given a Mac program which normally takes much mouse events and keyboard
  77. >input, is it possible (easily/with difficulty) to have that program run
  78. >automatically with the input being generated by another program?
  79.  
  80. Well, set "null events" on, and patch into the jGNEFilter. For
  81. every NULL event, instead add your own keyDown events, with a nullEvent
  82. sprinkled in here & yjere for good measure and recovery.
  83.  
  84. However, affecting someone elses jGNEFilter means patching in on
  85. INIT time; so you'll have to have a cool INIT/APPL combo.
  86.  
  87. Cheers,
  88.  
  89.                             / h+
  90.  
  91. - -- 
  92.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  93.  Engineering: "How will this work?" Science: "Why will this work?" Management:
  94.  "When will this work?"  Liberal Arts: "Do you want fries with that?"
  95.                      -- Jesse N. Schell
  96.  
  97. +++++++++++++++++++++++++++
  98.  
  99. From: absurd@apple.apple.com (Tim Dierks, software saboteur)
  100. Date: Fri, 18 Dec 1992 22:23:37 GMT
  101. Organization: MacDTS Marauders
  102.  
  103. In article <1992Dec18.175034.23523@kth.se>, d88-jwa@dront.nada.kth.se (Jon
  104. Wtte) wrote:
  105. > In <1992Dec18.041429.22979@philmtl.philips.ca> ray@philmtl.philips.ca (Ray Dunn) writes:
  106. > However, affecting someone elses jGNEFilter means patching in on
  107. > INIT time; so you'll have to have a cool INIT/APPL combo.
  108.  
  109. Actually, jGNEFilter is not (currently) swapped at process switch times;
  110. if you change jGNEFilter in one app, you've changed it in all of them.
  111. This makes life a little scary for jGNEFilter writers; if more than one
  112. person patches this vector, the earlier ones are never allowed to go
  113. away, because pointers to their code are stashed somewhere unknown.
  114.  
  115. Scary, huh?
  116.  
  117. Tim Dierks
  118. MacDTS pinball addict (TM)
  119.  
  120. ---------------------------
  121.  
  122. From: cmcclary@ucs.indiana.edu (Charles McClary)
  123. Subject: Detecting reboot or startup
  124. Date: 15 Dec 92 16:40:03 GMT
  125. Organization: Indiana University
  126.  
  127. What is the best/preferred method for an application to detect if the
  128. system has been rebooted or restarted since it (the application) last ran.
  129.  
  130. Thanks,
  131. Charlie McClary
  132. Indiana Univ.
  133. cmcclary@indiana.edu
  134.  
  135. +++++++++++++++++++++++++++
  136.  
  137. From: steve.herman%express@freedom.msfc.nasa.gov (Steve Herman)
  138. Date: 16 Dec 92 19:44:51 GMT
  139. Organization: BCSS
  140.  
  141. In article <cmcclary-151292113831@mcclary-mac.ucs.indiana.edu>,
  142. cmcclary@ucs.indiana.edu (Charles McClary) wrote:
  143. > What is the best/preferred method for an application to detect if the
  144. > system has been rebooted or restarted since it (the application) last ran.
  145.  
  146.     At one time I had attempted to do this by doing the following:
  147.  
  148.     1.    Get the current time in seconds using GetDateTime()
  149.     2.    Get number of ticks since last startup using TickCount()
  150.     3.    Divide #2 by 60 to get seconds since startup.
  151.     4.    Subtract #3 from #1 to get time in seconds of startup
  152.     5.    Save this value to a file.
  153.     6.    Whenever my application would startup it would perform steps 1-4 and
  154. compare to the value stored in the file.  If the values matched, plus or
  155. minus a fudge factor I built in, then I would assume the machine had not
  156. been re-booted since I last ran.
  157.  
  158.     However, this would obviously break if the user changed the date/time on
  159. his Mac.  I also found out that TickCount is incremented during the
  160. vertical retrace interrupt and whenever this interupt is disabled the ticks
  161. are not incremented so it gradually loses time. On my particular machine it
  162. was losing almost a minute for each hour my machine was up.  This was going
  163. to make my built-in fudge factor unrealistic.
  164.  
  165.     I attempted to find another way to do this but eventually gave up.  I
  166. would like to know if you discover a reliable method.
  167.  
  168.  
  169. - ----------------------------------------------------
  170. - - Steve Herman - BCSS
  171. - - Boeing Computer Support Services
  172. - - Huntsville, AL
  173. - ----------------------------------------------------
  174.  
  175. +++++++++++++++++++++++++++
  176.  
  177. From: d88-jwa@dront.nada.kth.se (Jon Wtte)
  178. Date: 16 Dec 92 13:28:25 GMT
  179. Organization: Royal Institute of Technology, Stockholm, Sweden
  180.  
  181. In <cmcclary-151292113831@mcclary-mac.ucs.indiana.edu> cmcclary@ucs.indiana.edu (Charles McClary) writes:
  182.  
  183. >What is the best/preferred method for an application to detect if the
  184. >system has been rebooted or restarted since it (the application) last ran.
  185.  
  186. Install a gestalt selector with your own signature as selector code.
  187.  
  188. If it's there, the application run previously during this "session."
  189. The selector code should reside in the system heap, and could simply
  190. return a 0 as result; you would test for presence, not return code.
  191.  
  192. Cheers,
  193.  
  194.                         / h+
  195.  
  196. - -- 
  197.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  198.  
  199.    Nothing crashes like a Macintosh.
  200.                      -- Guy Kawasaki
  201.  
  202. +++++++++++++++++++++++++++
  203.  
  204. From: kent@lloyd.Camex.COM (Kent Borg)
  205. Organization: Camex Inc., Boston MA
  206. Date: Thu, 17 Dec 1992 18:19:10 EST
  207.  
  208. In article <1992Dec16.132825.13170@kth.se> d88-jwa@dront.nada.kth.se (Jon Wtte) writes:
  209. >In <cmcclary-151292113831@mcclary-mac.ucs.indiana.edu> cmcclary@ucs.indiana.edu (Charles McClary) writes:
  210. >
  211. >>What is the best/preferred method for an application to detect if the
  212. >>system has been rebooted or restarted since it (the application) last ran.
  213. >
  214. >Install a gestalt selector with your own signature as selector code.
  215. >
  216. >If it's there, the application run previously during this "session."
  217. >The selector code should reside in the system heap, and could simply
  218. >return a 0 as result; you would test for presence, not return code.
  219.  
  220. I expected Jon to post that answer.  He is right, do it that way.
  221. However, if you want to run on old systems which don't have Gestalt,
  222. there is another (related) approach.
  223.  
  224. Put a little something else in the System heap, note its location in a
  225. file, and check whether it is still there when you next launch.
  226. (Rather than using a file to record the address you might walk the
  227. heap to find it.  I doubt Apple will change the heap structure in
  228. *old* systems.)
  229.  
  230. Off the top of my head, I can't remember how an app can allocate a
  231. handle in the System heap and also prevent Multifinder from cleaning
  232. up and deleting it for you when you exit, but loading a resource into
  233. the System heap and then detaching it should work.  Shouldn't it?
  234.  
  235.  
  236. - --
  237. Kent Borg            kent@camex.com or kentborg@aol.com (when it is *working*)
  238.                                             H:(617) 776-6899  W:(617) 426-3577
  239. As always, things look better when some costs are left out.
  240.                               -Economist 3-28-92 p. 94
  241.  
  242. +++++++++++++++++++++++++++
  243.  
  244. From: tj@kona.cs.ucla.edu (Tom Johnson)
  245. Date: 18 Dec 92 18:12:53 GMT
  246. Organization: UCLA, Computer Science Department
  247.  
  248. cmcclary@ucs.indiana.edu (Charles McClary) asked:
  249. >>
  250. >>>What is the best/preferred method for an application to detect if the
  251. >>>system has been rebooted or restarted since it (the application) last ran.
  252.  
  253. And d88-jwa@dront.nada.kth.se (Jon Wtte) answered:
  254. >>
  255. >>Install a gestalt selector with your own signature as selector code.
  256. >>
  257.  
  258. In considering old systems that don't have Gestalt, kent@lloyd.Camex.COM
  259. (Kent Borg) suggested:
  260. >
  261. >Put a little something else in the System heap, note its location in a
  262. >file, and check whether it is still there when you next launch.
  263. >(Rather than using a file to record the address you might walk the
  264. >heap to find it.  I doubt Apple will change the heap structure in
  265. >*old* systems.)
  266. >
  267. >Off the top of my head, I can't remember how an app can allocate a
  268. >handle in the System heap and also prevent Multifinder from cleaning
  269. >up and deleting it for you when you exit, but loading a resource into
  270. >the System heap and then detaching it should work.  Shouldn't it?
  271. >
  272.  
  273. This reminded me of how I used to handle communication between a cdev and
  274. an INIT before Gestalt was available.  I simply installed a small driver
  275. and used it to pass variables back and forth.
  276.  
  277. For this purpose (detecting whether the machine has been rebooted, the
  278. driver wouldn't really have to do anything - it could be a very simple
  279. shell.  As with Jon's Gestalt method, you would simply check for an error
  280.  - in this case one returned by OpenDriver().
  281.  
  282. Tom
  283. - -- 
  284. Tom Johnson             "They say Confucious does his crossword with a pen."
  285. tj@cs.ucla.edu                               -Tori Amos
  286.  
  287. +++++++++++++++++++++++++++
  288.  
  289. From: paul@taniwha.UUCP (Paul Campbell)
  290. Date: 19 Dec 92 03:54:21 GMT
  291. Organization: Taniwha Systems Design
  292.  
  293. In article <cmcclary-151292113831@mcclary-mac.ucs.indiana.edu> cmcclary@ucs.indiana.edu (Charles McClary) writes:
  294. >What is the best/preferred method for an application to detect if the
  295. >system has been rebooted or restarted since it (the application) last ran.
  296.  
  297. Assuming you saved the time your app last ran in a file and resource and
  298. then read it back again into 'last_time_ran' then try:
  299.  
  300.     unsigned long    last_time_ran, now;
  301.  
  302.     ReadDateTime(&now);
  303.     if ((now - (TickCount()/CLOCKS_PER_SEC)) > last_time_ran) {
  304.         // - we rebooted since last time we ran
  305.     }
  306.  
  307.     Paul
  308. - -- 
  309. Paul Campbell    UUCP: ..!mtxinu!taniwha!paul     AppleLink: CAMPBELL.P
  310. Use up your Quayle jokes now while they're still good "Quayle for Pres. in '94"
  311.      Q: Why is Marilyn Quayle like Marion Barry?
  312.      A: They both suck a little dope.
  313.  
  314. ---------------------------
  315.  
  316. From: bowman@reed.edu (Mr. Stress Tensor)
  317. Subject: Software control of landscape/not landscape
  318. Date: 18 Dec 92 20:51:37 GMT
  319. Organization: Reed College, Portland, OR
  320.  
  321. What's the best way to force landscape printing?  It would be nice if PrGeneral
  322. would do it, but apparently it can't (?).  I'd love to be wrong about that.
  323. It seems a bad idea to mucking directly into the print record, since I certainly
  324. can't test on every printer there is.  It also seems like it might be possible
  325. to fake a mousedown in the Page Setup dialog so that it defaults to landscape,
  326. but I'd like, if possible, to be able to use the print record for various
  327. nefarious porpoises.
  328.  
  329. Thanks,
  330. bobo              In seeking the unattainable,
  331. bowman@reed.edu            simplicity only gets in the way.
  332. Ask not what's inside your head but what your head's inside of. - W. Mace
  333.  
  334. +++++++++++++++++++++++++++
  335.  
  336. From: engber@ils.nwu.edu (Mike Engber)
  337. Date: 22 Dec 92 14:51:06 GMT
  338. Organization: The Institute for the Learning Sciences
  339.  
  340.  
  341. Attached is the relevant code extracted from SaveATree. It's THINK C code.
  342.  
  343. Basically, there is no official way to get a landscape print record,
  344. but it's somewhat common knowledge that the orientation is controlled
  345. by single bit in the print record (once source for this info is
  346. MacRevealed vol 3). This bit is used for Apple printers and deskwriters
  347. - - don't have access to other types of printers to check it out.
  348.  
  349. My conservative approach is to:
  350.  1) flip the bit
  351.  2) use PrValidate to make sure I didn't trash the print record - i.e.
  352.     this driver can't handle this bit being flipped.
  353.  3) use PrGeneral to make sure flipping the bit put the print record
  354.     into landscape mode (instead of doing something else)
  355.  4) if 1-3 didn't work, I prompt the user to pick a landscape record
  356.     from the PrStlDialog I subsequently display. This is sure to work
  357.     unless the user screws up (I display the landscape Icon in the dialog
  358.     in an attempt to make it more foolproof).
  359.  5) Once I get a landscape record I save it away so I'll never have
  360.     to do this again. 
  361.  
  362. This should work pretty well. I don't think it violate any guidlines
  363. (too badly). And I've never had and problems reported wrt to SaveATree
  364. doing it. Some cavats:
  365.  
  366. 1) the printer must have PrGeneral implemented along with the getRotnOp
  367.    opcode (I assume most do nowadays)
  368.  
  369. 2) Older HP deswriter drivers have PrGeneral & getRotnOp implementd, but
  370.    don't return a success error code from PrGeneral. So flipping the bit
  371.    works, but since PrGeneral says it's didn't - I end up prompting the
  372.    user anyway. This bug has been fixed in the more recent drivers.
  373.  
  374. - -ME
  375.  
  376. - ---
  377.  
  378. void PrintPromptedStyle(THPrint printRecH, Boolean landscape){
  379.     Alert(DU_CenterALRT(landscape ? L_SETUP_ALERT_ID : P_SETUP_ALERT_ID),0L);
  380.     PrOpen();
  381.     PrStlDialog(printRecH);
  382.     PrClose();
  383. }
  384.  
  385. static Boolean PrRotn(THPrint printRecH, Boolean* landscape){
  386.     TGetRotnBlk rotnBlk;
  387.     
  388.     rotnBlk.iOpCode = getRotnOp;
  389.     rotnBlk.hPrint  = printRecH;
  390.     PrGeneral((Ptr)&rotnBlk);
  391.     
  392.     if(rotnBlk.iError == noErr){
  393.         *landscape = rotnBlk.fLandscape ? true : false;
  394.         return true;
  395.     }else{
  396.         return false;
  397.     }
  398. }
  399.  
  400. void PrintDefaultRotn(THPrint printRecH, Boolean landscape){
  401.     Boolean         is_landscape;
  402.     static TPrint   landscapeTPrint;
  403.     static TPrint   portraitTPrint;
  404.     static Boolean  landscapeStored = false;
  405.     static Boolean  portraitStored = false;
  406.     
  407.     PrOpen();
  408.     if(PrintError("\pprint.c: PrintDefaultRotn()","\pPrOpen") != noErr){
  409.         PrClose();
  410.         return;
  411.     }
  412.     
  413.     PrValidate(printRecH);
  414.     
  415.     if(PrRotn(printRecH,&is_landscape)){
  416.         if(is_landscape != landscape){
  417.             /* toggle the bit */
  418.             (*printRecH)->prStl.wDev ^= 0x02;
  419.             /* make sure it worked */
  420.             PrValidate(printRecH);
  421.             if(PrRotn(printRecH,&is_landscape) && is_landscape==landscape){
  422.                 PrClose();
  423.                 return;
  424.             }
  425.         }else{
  426.             /* it was ok to begin with */
  427.             PrClose();
  428.             return;
  429.         }
  430.     }
  431.     
  432.     /*
  433.         If we reach this point either PrGeneral/getRotnOp or the
  434.         bit toggling won't work on this printer. So we'll prompt
  435.         the user & display a style dlog (ugh!).
  436.     */
  437.         PrClose();
  438.         
  439.         if(landscape){
  440.             if(landscapeStored){
  441.                 **printRecH = landscapeTPrint;
  442.             }else{
  443.                 PrintPromptedStyle(printRecH,landscape);
  444.                 landscapeStored = true;
  445.                 landscapeTPrint = **printRecH;
  446.             }
  447.         }else{
  448.             if(portraitStored){
  449.                 **printRecH = portraitTPrint;
  450.             }else{
  451.                 PrintPromptedStyle(printRecH,landscape);
  452.                 portraitStored = true;
  453.                 portraitTPrint = **printRecH;
  454.             }
  455.         }
  456. }
  457.  
  458. ---------------------------
  459.  
  460. From: hanord@rubin.dbe (Haavard Nord)
  461. Subject: Preloading ALL code segments...?
  462. Date: 1 Dec 92 18:43:46 GMT
  463. Organization: Department of Biomedical Engineering
  464.  
  465. Maybe this is a common question, but I hope someone can help me anyway.
  466.  
  467. I have a faceless background application that communicates with a client
  468. (external 4D procedure) via PPC. The background application uses asynch
  469. PPC services, i.e. its completion routines are some sort of interrupt.
  470.  
  471. When such an interrupt is invoked, the mac thinks that the foreground
  472. application is still current. When the background application makes calls
  473. to procedures in other CODE segments, the segment loader isn't able to
  474. load anything for the background. I've tried setting the global CurMap
  475. variable with UseResFile(), but it does nothing.
  476.  
  477. The solution is to have all code segments preloaded. How can I do this?
  478. There are more than 30 segments, and some of these come from library
  479. files.  I could use the '-sn myseg=Main' option with Link, but that
  480. requires that I know all segments, and the number of segments may change
  481. when the program is modified.
  482.  
  483. Another solution is to initially make calls to all functions I intend to
  484. use from the interrupt procedure, but that is as stupid as using -sn.
  485.  
  486. So --- what can I do? How can I (easily) load all segments at once when
  487. the background application starts, or how can I use UseResFile()?
  488.  
  489. Thanks,
  490.  
  491. - -hanord
  492. - --
  493. ===============================================================================
  494.  Haavard Nord                                        email: hanord@ibt.unit.no
  495.  Dept. of Biomedical Engineering                     phone: +47 7 598685
  496.  Trondheim, Norway                                     fax: +47 7 598613
  497. ===============================================================================
  498.  
  499. +++++++++++++++++++++++++++
  500.  
  501. Organization: Royal Institute of Technology, Stockholm, Sweden
  502. Date: Tue, 1 Dec 1992 19:29:55 GMT
  503.  
  504. In <HANORD.92Dec1194346@rubin.dbe> hanord@rubin.dbe (Haavard Nord) writes:
  505.  
  506. >The solution is to have all code segments preloaded. How can I do this?
  507. >There are more than 30 segments, and some of these come from library
  508. >files.  I could use the '-sn myseg=Main' option with Link, but that
  509. >requires that I know all segments, and the number of segments may change
  510. >when the program is modified.
  511.  
  512. >Another solution is to initially make calls to all functions I intend to
  513. >use from the interrupt procedure, but that is as stupid as using -sn.
  514.  
  515. >So --- what can I do? How can I (easily) load all segments at once when
  516. >the background application starts, or how can I use UseResFile()?
  517.  
  518. You, of course, cannot load resources under interrupt time, since
  519. you can do NOTHING that would move memory, and loading resources
  520. or calling across boundaries certainly do.
  521.  
  522. Now, what do you want to do in an interrupt service routine that
  523. would be so complicated as to require intra-segment calls? That would
  524. probably take time, and time during interrupt handling is CRITICAL!
  525. The mac is COMPLETELY FROZEN during interrupt servicing, and you
  526. don't want to be cruel to your users, right?
  527.  
  528. What you should do, is pre-allocate what buffers you need, and
  529. store whatever data comes in there, and set a flag that your main
  530. event loop will see next time through, and THEN do whatever you
  531. want to do. This is the only safe & fair way of doing "it."
  532.  
  533. If you have to pre-load all code resources, just do a simple:
  534.  
  535. void
  536. PreLoadAllCode ( void )
  537. {
  538.     Handle h ;
  539.     int i ;
  540.  
  541.     SetResLoad ( 0 ) ;
  542.  
  543.     for ( i = Count1Resources ( 'CODE' ) ; i > 0 ; i -- ) {
  544.  
  545.         h = Get1IndResource ( 'CODE' , i ) ;
  546.         if ( * h ) {
  547.  
  548.             HLock ( h ) ;
  549.  
  550.         } else {
  551.  
  552.             LoadResource ( h ) ;
  553.             if ( ResError ( ) ) {
  554.  
  555.                 SetResLoad ( 1 ) ;
  556.                 FailHorribly ( ResError ( ) ) ;
  557.  
  558.             } else {
  559.  
  560.                 HUnlock ( h ) ;
  561.                 MoveHHi ( h ) ;
  562.                 HLock ( h ) ;
  563.             }
  564.         }
  565.     }
  566.  
  567.     SetResLoad ( 1 ) ;
  568. }
  569.  
  570.  
  571. But, as I said, since you can call virtually NO toolbox traps
  572. either directly or indirectly during interrupt time; don't.
  573. And without calling the toolbox, there's not much more you can
  574. do but set a flag, and maybe queue a pre-prepared reply.
  575.  
  576. Cheers,
  577.  
  578.                             / h+
  579.  
  580. - -- 
  581.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  582.  
  583.   "From now on I will re-label the EQ on the deck as Fizz and Wobble
  584.    instead of HF and LF."
  585.  
  586. +++++++++++++++++++++++++++
  587.  
  588. From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  589. Date: 2 Dec 92 09:07:54 +1300
  590. Organization: University of Waikato, Hamilton, New Zealand
  591.  
  592. In article <HANORD.92Dec1194346@rubin.dbe>, hanord@rubin.dbe (Haavard Nord) writes:
  593. > Maybe this is a common question, but I hope someone can help me anyway.
  594. >
  595. > I have a faceless background application that communicates with a client
  596. > (external 4D procedure) via PPC. The background application uses asynch
  597. > PPC services, i.e. its completion routines are some sort of interrupt.
  598. >
  599. > When such an interrupt is invoked, the mac thinks that the foreground
  600. > application is still current. When the background application makes calls
  601. > to procedures in other CODE segments, the segment loader isn't able to
  602. > load anything for the background. I've tried setting the global CurMap
  603. > variable with UseResFile(), but it does nothing.
  604.  
  605. Remember that loading code segments means allocating memory, which means
  606. you can't do it at interrupt time.
  607.  
  608. > The solution is to have all code segments preloaded.
  609.  
  610. This is the right idea.
  611.  
  612. > How can I do this?
  613. > There are more than 30 segments, and some of these come from library
  614. > files.  I could use the '-sn myseg=Main' option with Link, but that
  615. > requires that I know all segments, and the number of segments may change
  616. > when the program is modified.
  617.  
  618. There's another directive , '-sg', which, among other things, takes the
  619. segment names in the opposite order to '-sn'. If you just use it in a form like
  620.  
  621.     -sg Everything
  622.  
  623. then *all* your code gets put into a single segment called "Everything".
  624. This is probably the simplest solution, if your program isn't too large.
  625.  
  626. > Another solution is to initially make calls to all functions I intend to
  627. > use from the interrupt procedure, but that is as stupid as using -sn.
  628.  
  629. It may be clumsy, but in many cases it's the only way. What you actually have
  630. to do is make a call to one routine in every *segment* that contains routines
  631. that might be used by your interrupt code. You could add a dummy routine to
  632. each such segment, specifically for this purpose.
  633.  
  634. This means you have to keep careful track of the segments in your program.
  635. But do you really need over 30 of them? You're probably better off merging
  636. a few of them with -sn or -sg directives.
  637.  
  638. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  639. Computer Services Dept                     fax: +64-7-838-4066
  640. University of Waikato            electric mail: ldo@waikato.ac.nz
  641. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  642.  
  643. +++++++++++++++++++++++++++
  644.  
  645. From: keith@taligent.com (Keith Rollin)
  646. Organization: Taligent
  647. Date: Tue, 1 Dec 1992 21:14:23 GMT
  648.  
  649. In article <HANORD.92Dec1194346@rubin.dbe>, hanord@rubin.dbe (Haavard Nord)
  650. wrote:
  651. > The solution is to have all code segments preloaded. How can I do this?
  652. > There are more than 30 segments, and some of these come from library
  653. > files.
  654.  
  655. int i;
  656. for (i = 0; i < kNumberOfSegs; ++i)
  657.     LoadSeg(i);
  658.  
  659. - -----
  660. Keith Rollin
  661. Phantom Programmer
  662. Taligent, Inc.
  663.  
  664. +++++++++++++++++++++++++++
  665.  
  666. From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  667. Date: 2 Dec 92 17:32:50 +1300
  668. Organization: University of Waikato, Hamilton, New Zealand
  669.  
  670. tte) writes:
  671. >
  672. > If you have to pre-load all code resources, just do a simple:
  673. >
  674. > void
  675. > PreLoadAllCode ( void )
  676. > {
  677. >     Handle h ;
  678. >     int i ;
  679. >
  680. >     SetResLoad ( 0 ) ;
  681. >
  682. >     for ( i = Count1Resources ( 'CODE' ) ; i > 0 ; i -- ) {
  683. >
  684. >         h = Get1IndResource ( 'CODE' , i ) ;
  685. >         if ( * h ) {
  686. >
  687. >             HLock ( h ) ;
  688. >
  689. >         } else {
  690. >
  691. >             LoadResource ( h ) ;
  692. >             if ( ResError ( ) ) {
  693. >
  694. >                 SetResLoad ( 1 ) ;
  695. >                 FailHorribly ( ResError ( ) ) ;
  696. >
  697. >             } else {
  698. >
  699. >                 HUnlock ( h ) ;
  700. >                 MoveHHi ( h ) ;
  701. >                 HLock ( h ) ;
  702. >             }
  703. >         }
  704. >     }
  705. >
  706. >     SetResLoad ( 1 ) ;
  707. > }
  708.  
  709. This routine isn't going to help. It's just a way of doing at run time
  710. what you can do at link time by specifying "-ra =preload". Sure, the CODE
  711. resources will all be in memory, but the jump tables aren't going to be
  712. set up. The segment loader will still make its own Resource Manager calls
  713. to find those segments, which will mean traversing resource maps, which is
  714. not going to work very nicely at interrupt time.
  715.  
  716. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  717. Computer Services Dept                     fax: +64-7-838-4066
  718. University of Waikato            electric mail: ldo@waikato.ac.nz
  719. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  720.  
  721. +++++++++++++++++++++++++++
  722.  
  723. From: absurd@apple.apple.com (Tim Dierks, software saboteur)
  724. Date: Wed, 2 Dec 1992 07:48:39 GMT
  725. Organization: MacDTS Marauders
  726.  
  727. In article <keith-011292131150@kip-15.taligent.com>, keith@taligent.com
  728. (Keith Rollin) wrote:
  729. > In article <HANORD.92Dec1194346@rubin.dbe>, hanord@rubin.dbe (Haavard Nord)
  730. > wrote:
  731. > > 
  732. > > The solution is to have all code segments preloaded. How can I do this?
  733. > > There are more than 30 segments, and some of these come from library
  734. > > files.
  735. > int i;
  736. > for (i = 0; i < kNumberOfSegs; ++i)
  737. >     LoadSeg(i);
  738. > -----
  739. > Keith Rollin
  740. > Phantom Programmer
  741. > Taligent, Inc.
  742.  
  743. I really hate to contradict Mr. Rollin, because there's a certain
  744. lurking suspicion that I could be incorrect, but this won't help
  745. for 3 reasons: first, LoadSeg is a very special trap; it requires
  746. that the code that calls it be structured in a particular way:
  747. first, the offset, hard coded as a constant into the code (2 bytes),
  748. then an instruction which loads the segment number onto the stack
  749. (4 bytes) and the LoadSeg trap (2 bytes).  All this makes a jump
  750. table entry, and is described and depicted on page 61 of Inside
  751. Mac II.  Second, LoadSeg never returns, because it's intended only
  752. as a mechanism for dispatching to routines in unloaded segments;
  753. this will cause this loop to never get to its second iteration.
  754. Third, due to these limitations, there isn't any prototype for
  755. LoadSeg; as far as I know, it can't be called from C or Pascal
  756. without writing your own prototype (and then would be very
  757. difficult to call correctly).
  758.  
  759. Tim Dierks
  760. Speaking solely for himself
  761.  
  762. +++++++++++++++++++++++++++
  763.  
  764. From: scott@phylo.life.uiuc.edu (Scott Howard)
  765. Date: 2 Dec 92 15:05:11 GMT
  766. Organization: University of Illinois at Urbana
  767.  
  768. This seems to be too simple to work, but how about 
  769. Using ResEdit to Flag all your code Resources as Pre-Load
  770. and No-Purge?
  771. - --
  772. Coffee Facts from Dr. Science:
  773. 1) You can never brew coffee too strong.
  774. 2) You can never drink too much coffee.
  775. 3) Coffee does not make you nervous.  Your own inadequacies do that.
  776.    Coffee merely increases your perception of your own inadequacies.
  777. 4) Tea is to coffee as ginger ale is to Scotch.
  778.  
  779. +++++++++++++++++++++++++++
  780.  
  781. From: keith@taligent.com (Keith Rollin)
  782. Date: 2 Dec 92 20:50:17 GMT
  783. Organization: Taligent
  784.  
  785. In article <absurd-011292234220@seuss.apple.com>, absurd@apple.apple.com
  786. (Tim Dierks, software saboteur) wrote:
  787. > In article <keith-011292131150@kip-15.taligent.com>, keith@taligent.com
  788. > (Keith Rollin) wrote:
  789. > > 
  790. > > In article <HANORD.92Dec1194346@rubin.dbe>, hanord@rubin.dbe (Haavard Nord)
  791. > > wrote:
  792. > > > 
  793. > > > The solution is to have all code segments preloaded. How can I do this?
  794. > > > There are more than 30 segments, and some of these come from library
  795. > > > files.
  796. > > 
  797. > > int i;
  798. > > for (i = 0; i < kNumberOfSegs; ++i)
  799. > >     LoadSeg(i);
  800. > I really hate to contradict Mr. Rollin, because there's a certain
  801. > lurking suspicion that I could be incorrect, but this won't help
  802. > for 3 reasons: first, LoadSeg is a very special trap; it requires
  803. > that the code that calls it be structured in a particular way:
  804. > first, the offset, hard coded as a constant into the code (2 bytes),
  805. > then an instruction which loads the segment number onto the stack
  806. > (4 bytes) and the LoadSeg trap (2 bytes).  All this makes a jump
  807. > table entry, and is described and depicted on page 61 of Inside
  808. > Mac II.  Second, LoadSeg never returns, because it's intended only
  809. > as a mechanism for dispatching to routines in unloaded segments;
  810. > this will cause this loop to never get to its second iteration.
  811. > Third, due to these limitations, there isn't any prototype for
  812. > LoadSeg; as far as I know, it can't be called from C or Pascal
  813. > without writing your own prototype (and then would be very
  814. > difficult to call correctly).
  815.  
  816. I really hate to not contradict Mr. Dierks, but he's right. I was tricked
  817. into thinking that LoadSeg could be called by the THINK Reference. Although
  818. it the reference does say "LoadSeg is called indirectly...", it didn't jump
  819. out and say that one CAN'T call it directly. It also gave a high-level
  820. interface to the call. If I'd given the answer 2 seconds of thought before
  821. sending it, I'd've realized that you couldn't call LoadSeg.
  822.  
  823. Well, I guess I'm in good company for being wrong today. Lawrence just
  824. caught Jon in a boo-boo, too.
  825.  
  826. Calling a dummy function in each segment would be a way to go, but that's
  827. not fun. How about using a function loosely based on MacApp's
  828. PreLoadSegment function? First get the address of _LoadSeg with
  829. GetTrapAddress. Then call the following function instead of LoadSeg, like I
  830. showed above.
  831.  
  832.  
  833. EXPORT PROCEDURE RETURNABLELOADSEG(theSegNum:W)
  834.  
  835.     BEGIN    Save=D0-D2/A0-A2
  836.     IMPORT    LOADSEGADDRESS
  837.  
  838.     MOVE        LOADSEGADDRESS(A5),A0
  839.  
  840.     Move.W        theSegNum(FP),-(SP)  ; push the original parameter to loadseg
  841.     PEA            ComeBack+6             ; push a return address
  842.                                  ; loadseg will knock 6 off the return
  843. address
  844.     Jmp            (A0)                   ; Call the original loadseg
  845.  
  846. ComeBack
  847.  
  848.     Return                       ; Return to the real world
  849.     EndP
  850.  
  851.  
  852. - -----
  853. Keith Rollin
  854. Phantom Programmer
  855. Taligent, Inc.
  856.  
  857. +++++++++++++++++++++++++++
  858.  
  859. From: werner@soe.berkeley.edu (John Werner)
  860. Date: 2 Dec 1992 22:16:00 GMT
  861. Organization: UC Berkeley School of Education
  862.  
  863. In article <absurd-011292234220@seuss.apple.com>, Tim Dierks wrote:
  864. > In article <keith-011292131150@kip-15.taligent.com>, Keith Rollin:
  865. > > int i;
  866. > > for (i = 0; i < kNumberOfSegs; ++i)
  867. > >     LoadSeg(i);
  868. > > 
  869. > I really hate to contradict Mr. Rollin, because there's a certain
  870. > lurking suspicion that I could be incorrect, but this won't help
  871. > for 3 reasons: first, LoadSeg is a very special trap
  872.  
  873. How about something like this:
  874.  
  875. short num = Count1Resources('CODE');
  876. for (short i = 1; i <= num; i)) {
  877.    Handle hdl = Get1IndResource('CODE', I);
  878.    HLock(hdl);
  879.    HNoPurge(hdl);
  880. }
  881.  
  882. This should get all the segments into memory.  It won't change the jump
  883. table to say that they're already loaded.  But LoadSeg will take care of
  884. that (without moving memory) the first time a function in each segment is
  885. called, so it shouldn't matter.
  886.  
  887. [By the way, the article I'm following up to had a bogus distrution "comp".
  888.  I changed it to "world.]
  889.  
  890. - --
  891. John Werner                         werner@soe.berkeley.edu
  892. UC Berkeley School of Education     510-642-9651
  893.  
  894. +++++++++++++++++++++++++++
  895.  
  896. From: bowman@reed.edu (BoBoRamDos)
  897. Date: 2 Dec 92 23:22:40 GMT
  898. Organization: Reed College, Portland, OR
  899.  
  900. So, can you recover if RETURNABLELOADSEG fails?  That could be mighty handy,
  901. a bit easier than maintaining a separate heap for code segs, at least sometimes.
  902. Especially since SADE has a tendency to get very confused when doing that.
  903.  
  904. cheers,
  905. bobo              In seeking the unattainable,
  906. bowman@reed.edu            simplicity only gets in the way.
  907. Ask not what's inside your head but what your head's inside of. - W. Mace
  908.  
  909. +++++++++++++++++++++++++++
  910.  
  911. From: keith@taligent.com (Keith Rollin)
  912. Organization: Taligent
  913. Date: Thu, 3 Dec 1992 01:23:49 GMT
  914.  
  915. In article <1992Dec2.232240.3040@reed.edu>, bowman@reed.edu (BoBoRamDos)
  916. wrote:
  917. >So, can you recover if RETURNABLELOADSEG fails?  That could be mighty handy,
  918. >a bit easier than maintaining a separate heap for code segs, at least sometimes.
  919. >Especially since SADE has a tendency to get very confused when doing that.
  920.  
  921.  
  922. Aw, you would bring that up. One thing that you could do have
  923. RETURNABLELOADSEG call GetResource for the CODE segment you are interested
  924. in. If that fails, then RETURNABLELOADSEG returns FALSE. If the CODE
  925. segment loads, then call LoadSeg and return TRUE. MacApp's version does
  926. this; I just didn't show it in my posting.
  927.  
  928. - -----
  929. Keith Rollin
  930. Phantom Programmer
  931. Taligent, Inc.
  932.  
  933. +++++++++++++++++++++++++++
  934.  
  935. From: keith@taligent.com (Keith Rollin)
  936. Organization: Taligent
  937. Date: Thu, 3 Dec 1992 01:27:20 GMT
  938.  
  939. In article <werner-021292141545@128.32.157.31>, werner@soe.berkeley.edu
  940. (John Werner) wrote:
  941. > How about something like this:
  942. > short num = Count1Resources('CODE');
  943. > for (short i = 1; i <= num; i)) {
  944. >    Handle hdl = Get1IndResource('CODE', I);
  945. >    HLock(hdl);
  946. >    HNoPurge(hdl);
  947. > }
  948. > This should get all the segments into memory.  It won't change the jump
  949. > table to say that they're already loaded.  But LoadSeg will take care of
  950. > that (without moving memory) the first time a function in each segment is
  951. > called, so it shouldn't matter.
  952.  
  953. As Lawrence pointed out, the problem with this is that LoadSeg will *still*
  954. call GetResource. This would require that the proper resource chain be
  955. swapped in. However, that's not the case under the circumstances of the
  956. original poster's question.
  957.  
  958. By the way, you'd probably want a MoveHHi() in there before the HLock().
  959. Better yet, use HLockHi(). And if the handle's locked, you don't need the
  960. call to HNoPurge().
  961.  
  962. - -----
  963. Keith Rollin
  964. Phantom Programmer
  965. Taligent, Inc.
  966.  
  967. +++++++++++++++++++++++++++
  968.  
  969. Organization: Royal Institute of Technology, Stockholm, Sweden
  970. Date: Thu, 3 Dec 1992 12:24:18 GMT
  971.  
  972. In <1992Dec2.173250.12571@waikato.ac.nz> ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  973.  
  974. >This routine isn't going to help. It's just a way of doing at run time
  975.  
  976. Well, no. Actually, yes, it will help prevent spinning the disk
  977. re right about it not changing the jump
  978. tables. For that you could include a function in each and every
  979. segment that got called on startup to load the segment.
  980.  
  981. OR: (Hack warning) You could walk the jump table and patch it up yourself.
  982. s not too hard actually, as long as you make sure to flush the cache.
  983. - -- 
  984.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  985.  
  986.   "From now on I will re-label the EQ on the deck as Fizz and Wobble
  987.    instead of HF and LF."
  988.  
  989. +++++++++++++++++++++++++++
  990.  
  991. From: bobert@informix.com (Robert Murphy)
  992. Date: 3 Dec 92 00:49:33 GMT
  993. Organization: Informix Software, Inc.
  994.  
  995. Haavard Nord started this thread by talking about problems he is having in
  996. an interrupt-time completion routine.  It calls code in another code segment
  997. which may not be loaded, and this seems to cause all kinds of trouble which
  998. he hoped to avoid by preloading all his code segments.  A number of people
  999. have made suggestions about how to do this and how you shouldn't try to load
  1000. code segments at interrupt time (it does the evil deed of moving memory).
  1001.  
  1002. Having just been thrashing with PPC completion routines, I'd make one more
  1003. remark.  If you're going to call a routine outside the current code segment
  1004. at interrupt time, *** MAKE SURE YOUR A5 WORLD IS SET UP CORRECTLY *** !!!!!
  1005. Otherwise, you will probably be calling code in some other app, and Gopod
  1006. help you if you try to use access any global or static variables.  For more
  1007. info on screwing around with A5 worlds in a completion routine, see IM VI
  1008. p. 28-14, and also Tech Note #256, which has a really great discussion of
  1009. A5 worlds in general and why you would want to worry about them.
  1010.  
  1011. Bob Murphy
  1012.  
  1013. +++++++++++++++++++++++++++
  1014.  
  1015. From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  1016. Date: 4 Dec 92 11:17:42 +1300
  1017. Organization: University of Waikato, Hamilton, New Zealand
  1018.  
  1019. tte) writes:
  1020. > In <1992Dec2.173250.12571@waikato.ac.nz> ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  1021. >
  1022. >>This routine isn't going to help. It's just a way of doing at run time
  1023. >
  1024. > Well, no. Actually, yes, it will help prevent spinning the disk
  1025. > for PowerBook users...
  1026.  
  1027. Something else I thought of: I remember a tech note that appeared when the
  1028. Mac Plus first came out. It described a special "fast load" mode in the
  1029. Resource Manager, whereby (if I recall correctly) if you had a bunch of
  1030. preloadable resources stored contiguously in a resource file, they would be
  1031. read into memory with some minimum number of disk reads when the file was
  1032. opened.
  1033.  
  1034. Somehow this information never made it into Inside Mac. Is it still true? If
  1035. so, it's another advantage of specifying the preload bit over Jon's run-time
  1036. solution. :-)
  1037.  
  1038. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  1039. Computer Services Dept                     fax: +64-7-838-4066
  1040. University of Waikato            electric mail: ldo@waikato.ac.nz
  1041. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00
  1042.  
  1043. +++++++++++++++++++++++++++
  1044.  
  1045. From: anadig@otago.ac.nz
  1046. Date: 8 Dec 92 08:39:27 GMT
  1047. Organization: University of Otago, Dunedin, New Zealand
  1048.  
  1049. In article <1992Dec4.111742.12613@waikato.ac.nz>, ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
  1050.  
  1051. > Something else I thought of: I remember a tech note that appeared when the
  1052. > Mac Plus first came out. It described a special "fast load" mode in the
  1053. > Resource Manager, whereby (if I recall correctly) if you had a bunch of
  1054. > preloadable resources stored contiguously in a resource file, they would be
  1055. > read into memory with some minimum number of disk reads when the file was
  1056. > opened.
  1057.  
  1058. I think you are thinking of JumpStart: not so much a tech note as a utility. It
  1059. rearranged your resource fork so that things were in the order that they
  1060. loaded, using a log that it acquired with another tool. Cute idea: I remember
  1061. that it had a few dangerous modes in which it would relocate the resource map
  1062. and do a few semi-legal things as well. It certainly sped up application
  1063. startup from floppies.
  1064.  
  1065. The simpler thing that you can do yourself - and UpdateMaker actually does it
  1066. :-) - is write out all the preloaded resources first when you are building an
  1067. application. As a result applications updated with UpdateMaker may actually
  1068. start up a little bit quicker than the original...
  1069.  
  1070.                                                  
  1071. Michael(tm) Hamel
  1072.  
  1073. Analog Digital Instruments, Dunedin, New Zealand.
  1074.  
  1075. +++++++++++++++++++++++++++
  1076.  
  1077. From: milton@ccu.umanitoba.ca (Dave Milton)
  1078. Date: 7 Dec 92 17:59:57 GMT
  1079. Organization: University of Manitoba, Winnipeg, Canada
  1080.  
  1081. One way to force loading of all segments is to place a simple routine
  1082. which does nothing into each segment. For argument sake you could call
  1083. this ForceName where the Name is the name of the segment; you could
  1084. also use the segment number. At application startup time you can then
  1085. force all of these segments to load by calling all of those routines.
  1086. For example, if you have one segment called printing, a second called
  1087. search, and a third called connect then you could place into your init
  1088. segment a routine
  1089.     void ForceLoadSeg()
  1090.     {
  1091.        ForcePrinting();
  1092.        ForceSearch();
  1093.        ForceConnect();
  1094.     }
  1095.  
  1096. Each code segment would contain a routine that does nothing:
  1097.     void ForcePrinting() {}  // or ForceSearch or ForceConnect
  1098.  
  1099. Doing something like the above will cause all modules to load. Since I
  1100. came in at the middle of this thread I may have missed the purpose of
  1101. loading all the code modules at one time. I do have a misgiving about
  1102. doing this kind of thing: it defeats the entire purpose of having a
  1103. program broken into segments. I am under the impression that having
  1104. seperate code segments will reduce the memory footprint of your program.
  1105. A properly segmented program will use much less memory during normal
  1106. operations than a program that simply loads all its segments when it
  1107. starts up. This technique may be useful for testing whether your program
  1108. works well under low memory conditions but beyond that its value is
  1109. dubious IMHO.
  1110.  
  1111. Hope this helps
  1112. - -- 
  1113. David Milton, University of Manitoba, Winnipeg, Canada. (204)788-6346
  1114. Internet: milton@ccu.UManitoba.CA   Bitnet: milton@UOFMCC
  1115.  
  1116. +++++++++++++++++++++++++++
  1117.  
  1118. From: scott@mcl.ucsb.edu (Scott Bronson)
  1119. Date: 11 Dec 92 02:37:17 GMT
  1120.  
  1121. In <BywHzy.4C9@ccu.umanitoba.ca> milton@ccu.umanitoba.ca (Dave Milton) writes:
  1122.  
  1123. >One way to force loading of all segments is to place a simple routine
  1124. >o load by calling all of those routines.
  1125. >For example, if you have one segment called printing, a second called
  1126. >search, and a third called connect then you could place into your init
  1127. >segment a routine
  1128. >    void ForceLoadSeg()
  1129. >    {
  1130. >       ForcePrinting();
  1131. >       ForceSearch();
  1132. >       ForceConnect();
  1133. >    }
  1134.  
  1135. >Each code segment would contain a routine that does nothing:
  1136. >    void ForcePrinting() {}  // or ForceSearch or ForceConnect
  1137.  
  1138. A tiny little thought...
  1139.  
  1140. In the (perhaps paranoid) fear that some smart C compiler would
  1141. label my functions as dead code and strip them and calls to them
  1142. (after all, they are optimizing a needless segment load out, quite
  1143. a good optimization IMHO), I simply split my InitMacintosh routine
  1144. into my segments:
  1145.  
  1146. void InitMacintosh()
  1147. {
  1148.     InitGraf, InitFonts, InitWindows...
  1149.     InitPrinting();
  1150.     InitSearch();
  1151.     InitConnect();
  1152. }
  1153.  
  1154. Told ya it was insignificant; I thought it was cool...
  1155.  
  1156. +++++++++++++++++++++++++++
  1157.  
  1158. From: thomas@camino.mic.cl (Thomas Fruin)
  1159. Date: 27 Dec 92 00:55:22 GMT
  1160. Organization: El Camino
  1161.  
  1162.  
  1163. In article <keith-021292172408@kip-15.taligent.com> (comp.sys.mac.programmer),
  1164. keith@taligent.com (Keith Rollin) writes:
  1165.  
  1166. >By the way, you'd probably want a MoveHHi() in there before the HLock().
  1167. >Better yet, use HLockHi(). And if the handle's locked, you don't need the
  1168. >call to HNoPurge().
  1169. >
  1170. >-----
  1171. >Keith Rollin
  1172. >Phantom Programmer
  1173. >Taligent, Inc.
  1174.  
  1175. Hey, what is HLockHi()? I can guess what it does, but I have never seen it
  1176. documented anywhere. Is it MPW glue or a real trap?
  1177.  
  1178. - -- Thomas Fruin
  1179.  
  1180.    thomas@camino.mic.cl
  1181.  
  1182. +++++++++++++++++++++++++++
  1183.  
  1184. From: d88-jwa@dront.nada.kth.se (Jon Wtte)
  1185. Date: 27 Dec 92 09:46:37 GMT
  1186. Organization: Royal Institute of Technology, Stockholm, Sweden
  1187.  
  1188. In <0105013E.m27dq5@camino.mic.cl> thomas@camino.mic.cl (Thomas Fruin) writes:
  1189.  
  1190.  
  1191. >Hey, what is HLockHi()? I can guess what it does, but I have never seen it
  1192. >documented anywhere. Is it MPW glue or a real trap?
  1193.  
  1194. It's glue taking advantage of the passing conventions for
  1195. handle traps to optimize stack and register usage (i.e.
  1196. don't have to adjust stack or reload registers between
  1197. the traps)
  1198.  
  1199. And it's not only in MPW.
  1200.  
  1201. Cheers,
  1202.  
  1203.                         / h+
  1204.  
  1205. - -- 
  1206.  -- Jon W{tte, h+@nada.kth.se, Mac Hacker Deluxe --
  1207.  Engineering: "How will this work?" Science: "Why will this work?" Management:
  1208.  "When will this work?"  Liberal Arts: "Do you want fries with that?"
  1209.                      -- Jesse N. Schell
  1210.  
  1211. ---------------------------
  1212.  
  1213. End of C.S.M.P. Digest
  1214. **********************
  1215.